package cn.xluobo.business.wechat.miniapp.course.service;

import cn.xluobo.business.sc.student.domain.req.ReqSearchStudentCourseCla;
import cn.xluobo.business.sc.student.domain.resp.RespCourseClaStudent;
import cn.xluobo.business.sc.student.service.BusinessScStudentCourseService;
import cn.xluobo.business.sys.admin.enums.RoleEnum;
import cn.xluobo.business.sys.admin.service.ISysUserService;
import cn.xluobo.config.login.LoginUser;
import cn.xluobo.core.page.RespPage;
import cn.xluobo.utils.LoginUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author ：KingLong
 * @date ：Created in 2020/11/5 17:17
 */
@Service
@Transactional
public class WechatMiniCourseService {

    @Autowired
    private BusinessScStudentCourseService studentCourseService;
    @Autowired
    private ISysUserService userService;

    /**
     * 班级 课程 学生列表
     * @param reqSearchStudentCourseCla
     * @return
     */
    public RespPage<RespCourseClaStudent> searchCourseClaStudent(ReqSearchStudentCourseCla reqSearchStudentCourseCla) {
        LoginUser loginUser = LoginUserUtil.getLoginUser();
        Long deptId = loginUser.getDeptId();

        // 是否拥有管理角色
        boolean allSchoolData = userService.checkUserHasAnyRole(loginUser.getUserId(), loginUser.getNowTenantId(), new String[]{
                RoleEnum.SCHOOL_MANAGER.getRoleCode(),
                RoleEnum.TEACHING_MANAGER.getRoleCode()
        });

        reqSearchStudentCourseCla.setDeptId(deptId);
        reqSearchStudentCourseCla.setUserId(loginUser.getUserId());

        return studentCourseService.searchCourseClaStudent(reqSearchStudentCourseCla);
    }

}
